package com.foreknow.controller;

import com.foreknow.model.UserEntity;
import com.foreknow.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
public class MainController {
    @Autowired
    private UserRepository userRepository;
    @RequestMapping(value = "/admin/users",method = RequestMethod.GET)
    public String getUser(ModelMap modelMap){
        //调用持久层的方法来查询所有用户的信息
        List<UserEntity> list = userRepository.findAll();
        //将查询到的list保存到ModelMap中
        modelMap.addAttribute("list",list);
        return "admin/users";
    }
}
